package com.tedu.myblog.serviceImpl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.tedu.myblog.dao.BlogDao;
import com.tedu.myblog.entity.Blog;
import com.tedu.myblog.pojo.BlogQuery;
import com.tedu.myblog.pojo.SearchBlog;
import com.tedu.myblog.pojo.ShowBlog;
import com.tedu.myblog.service.BlogService;
@Service
public class BlogServiceImpl implements BlogService {
	@Autowired
	private BlogDao blogDao;
	//保存录入的博客信息
	public int saveBlog(Blog blog) {
		// 初始化
		blog.setCreateTime(new Date());// 创建时间
		blog.setUpdateTime(new Date());// 修改时间
		blog.setViews(0);// 浏览数目
		blog.setCommentCount(0);// 访问数
		return blogDao.saveBlog(blog);
	}

	
	//查询文章管理列表
	@Override
	public List<BlogQuery> getAllBlog() {
		return blogDao.getAllBlogQuery();
	}
	
	//删除博客
	@Override
	public void deleteBlog(Long id) {
		blogDao.deleteBlog(id);
	}

	//查询编辑修改的文章
	public ShowBlog getBlogById(Long id) {
		return blogDao.getBlogById(id);
	}

	//编辑修改文章
	public int updateBlog(ShowBlog showBlog) {
		showBlog.setUpdateTime(new Date());
		return blogDao.updateBlog(showBlog);
	}

	//搜索博客管理列表
	public List<BlogQuery> getBlogBySearch(SearchBlog searchBlog) {
		return blogDao.searchByTitleAndType(searchBlog);
	}

}
